 
 <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>基础菜单 - 页面元素 - Layui</title>
<meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  <script>
  ;!function(){self!==parent&&(location.href="//www.baidu.com/")}();
  </script>
  <link rel="stylesheet" href="../../layui/dist/css/layui.css" media="all">
  <link rel="stylesheet" href="../../static/css/global.css" media="all">
</head>
<body><div class="layui-header header header-doc" autumn="">
  <div class="layui-container">
    <a class="logo" href="../../index.html">
      <img src="../../static/images/layui/logo.png" alt="layui">
    </a>
    <div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
    <div class="layui-hide-xs site-notice"></div>
    
    <ul class="layui-nav" id="LAY_NAV_TOP">
      <li class="layui-nav-item layui-this">
        <a href="../index.html">文档</a> 
      </li>
      <li class="layui-nav-item ">
        <a href="../../demo/index.html">示例</a>
      </li>
      
      <li class="layui-nav-item">
        <a href="javascript:;">
          <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>--> 
          周边
        </a>
        <dl class="layui-nav-child layui-nav-child-c">  
          <dd class="layui-hide-sm layui-show-xs" lay-unselect="">
            <a href="javascript:window.open('https://gitee.com/sentsin/layui/issues');" target="_blank" rel="nofollow">问题反馈</a>
            <hr>
          </dd>
          
          <dd lay-unselect=""><a href="../../alone.html" target="_blank" lay-unselect="">独立组件</a></dd>
          <dd lay-unselect=""><a href="../../extend/index.html" target="_blank">扩展组件</a></dd>
        </dl>
      </li>
      
      
    </ul>
  </div>
</div>
 
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
 
<ul class="site-dir">
  <li><a href="#use"><cite>菜单结构</cite></a></li>
  <li><a href="#type"><cite>菜单项类型</cite></a></li>
  <li><a href="#options"><cite>菜单项参数</cite></a></li>
  <li><a href="#on"><cite>事件触发</cite></a></li>
</ul>
<div class="layui-container layui-row">
  
<div class="layui-col-md3">
  <div class="layui-panel site-menu">
    <ul class="layui-menu layui-menu-lg">
      <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
        <div class="layui-menu-body-title">
          基础说明
        </div>
        <hr>
        <ul>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../index.html">
                <span>开始使用 </span> 
                <span class="layui-font-12 layui-font-gray">Getting Started</span>
              </a>
              
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/infrastructure.html">
                <span>底层方法 </span>
                <span class="layui-font-12 layui-font-gray">基础支撑</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/element.html">
                <span>页面元素 </span>
                <span class="layui-font-12 layui-font-gray">规范 公共类 属性</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/modules.html">
                <span>模块规范 </span>
                <span class="layui-font-12 layui-font-gray">使用 扩展</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/faq.html">
                <span>常见问题 </span>
                <span class="layui-font-12 layui-font-gray">FAQ</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../base/changelog.html">
                <span>更新日志 </span>
                <span class="layui-font-12 layui-font-gray">changelog</span>
                
                  <span class="layui-badge-dot"></span>
                
              </a>
            </div>
          </li>
        </ul>
      </li>
      
      <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
        <div class="layui-menu-body-title">
          页面元素
        </div>
        <hr>
        <ul>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="layout.html">
                <span>布局 </span>
                <span class="layui-font-12 layui-font-gray">栅格 后台管理布局</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="color.html">
                <span>颜色 </span>
                <span class="layui-font-12 layui-font-gray">主色调 颜色搭配</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="icon.html">
                <span>图标 </span>
                <span class="layui-font-12 layui-font-gray">iconfont 字体图标</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="anim.html">
                <span>动画 </span>
                <span class="layui-font-12 layui-font-gray">内置 CSS3 动画</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="button.html">
                <span>按钮 </span>
                <span class="layui-font-12 layui-font-gray">button</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="form.html">
                <span>表单 </span>
                <span class="layui-font-12 layui-font-gray">form 元素集合</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="nav.html">
                <span>导航 </span>
                <span class="layui-font-12 layui-font-gray">nav 面包屑</span>
              </a>
            </div>
          </li>
          <li class="layui-menu-item-checked2">
            <div class="layui-menu-body-title">
              <a href="">
                <span>菜单 </span>
                <span class="layui-font-12 layui-font-gray">menu 基础菜单</span>
                
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="tab.html">
                <span>选项卡 </span>
                <span class="layui-font-12 layui-font-gray">Tabs 切换</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="progress.html">
                <span>进度条 </span>
                <span class="layui-font-12 layui-font-gray">progress</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="panel.html">
                <span>面板 </span>
                <span class="layui-font-12 layui-font-gray">panel 卡片 折叠</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="table.html">
                <span>表格 </span>
                <span class="layui-font-12 layui-font-gray">静态 table</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="badge.html">
                <span>徽章 </span>
                <span class="layui-font-12 layui-font-gray">小圆点  小边框</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="timeline.html">
                <span>时间线 </span>
                <span class="layui-font-12 layui-font-gray">timeline</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="auxiliar.html">
                <span>辅助 </span>
                <span class="layui-font-12 layui-font-gray">引用 字段集 横线等</span>
              </a>
            </div>
          </li>
        </ul>
      </li>
      
      <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
        <div class="layui-menu-body-title">
          内置模块
        </div>
        <hr>
        <ul>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/layer.html">
                <span>弹出层 </span>
                <span class="layui-font-12 layui-font-gray">layer</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/laydate.html">
                <span>日期与时间选择 </span>
                <span class="layui-font-12 layui-font-gray">laydate</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/laypage.html">
                <span>分页 </span>
                <span class="layui-font-12 layui-font-gray">laypage</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/laytpl.html">
                <span>模板引擎 </span>
                <span class="layui-font-12 layui-font-gray">laytpl</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/table.html">
                <span>数据表格 </span>
                <span class="layui-font-12 layui-font-gray">table</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/form.html">
                <span>表单 </span>
                <span class="layui-font-12 layui-font-gray">form</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/upload.html">
                <span>文件上传 </span>
                <span class="layui-font-12 layui-font-gray">upload</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/dropdown.html">
                <span>下拉菜单 </span>
                <span class="layui-font-12 layui-font-gray">dropdown</span>
                
                  <span class="layui-badge-dot"></span>
                
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/transfer.html">
                <span>穿梭框 </span>
                <span class="layui-font-12 layui-font-gray">transfer</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/tree.html">
                <span>树形组件 </span>
                <span class="layui-font-12 layui-font-gray">tree</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/colorpicker.html">
                <span>颜色选择器 </span>
                <span class="layui-font-12 layui-font-gray">colorpicker</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/element.html">
                <span>常用元素操作 </span>
                <span class="layui-font-12 layui-font-gray">element</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/slider.html">
                <span>滑块 </span>
                <span class="layui-font-12 layui-font-gray">slider</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/rate.html">
                <span>评分 </span>
                <span class="layui-font-12 layui-font-gray">rate</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/carousel.html">
                <span>轮播 </span>
                <span class="layui-font-12 layui-font-gray">carousel</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/flow.html">
                <span>流加载 </span>
                <span class="layui-font-12 layui-font-gray">flow</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/util.html">
                <span>工具组件 </span>
                <span class="layui-font-12 layui-font-gray">util</span>
              </a>
            </div>
          </li>
          <li class="">
            <div class="layui-menu-body-title">
              <a href="../modules/code.html">
                <span>代码高亮显示 </span>
                <span class="layui-font-12 layui-font-gray">code</span>
              </a>
            </div>
          </li>
        </ul>
      </li>
    </ul>
  </div>
  <div class="layui-hide-v"> - </div>
</div>

  
  <div class="layui-col-md9 site-content">
    <h1 class="site-h1">基础菜单 - 页面元素</h1>
    <blockquote class="layui-elem-quote layui-text">
      菜单是页面必不可少的元素，我们希望它是通用的，所以在结构上，它的组成极其灵活。而事实上，在基础菜单还没有正式推出之前，垂直导航（layui-nav-tree）曾顶替了它的角色，尤其是在管理系统中发挥了举足轻重的作用。尽管它们本质上都属于「菜单」的范畴，但我们姑且约定将水平的称之为「导航」，垂直的称之为正统的「基础菜单」。它将十分有用，许多业务场景都能看到它的存在。
    </blockquote>
    <blockquote class="layui-elem-quote layui-text">
      可依赖的模块：<em>dropdown</em>
    </blockquote>
    
    
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="use">菜单结构</a></legend>
    </fieldset>
    <div class="site-text">
      <p>
        通常基础菜单是搭配面板（layui-panel）使用的，但这并不是必须的。基础菜单有它独有的样式结构，以下是一个基本的示例：
      </p>
      
      <div class="layui-tab layui-tab-brief layui-code-demo">
        <ul class="layui-tab-title">
          <li class="layui-this">代码</li>
          <li>预览</li>
        </ul>
        <div class="layui-tab-content layui-border layui-bg-gray">
          <div class="layui-tab-item layui-show">
            <pre class="layui-code layui-hide-v" id="docDemoCode1" lay-lang="HTML" lay-height="360px">
&lt;div class=&quot;layui-panel&quot;&gt;
  &lt;ul class=&quot;layui-menu&quot; id=&quot;docDemoMenu1&quot;&gt;
    &lt;li lay-options=&quot;{id: 100}&quot;&gt;
      &lt;div class=&quot;layui-menu-body-title&quot;&gt;menu item 1&lt;/div&gt;
    &lt;/li&gt;
    &lt;li lay-options=&quot;{id: 101}&quot;&gt;
      &lt;div class=&quot;layui-menu-body-title&quot;&gt;
        &lt;a href=&quot;#&quot;&gt;menu item 2 &lt;span class=&quot;layui-badge-dot&quot;&gt;&lt;/span&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/li&gt;
    &lt;li class=&quot;layui-menu-item-divider&quot;&gt;&lt;/li&gt;
    &lt;li class=&quot;layui-menu-item-group layui-menu-item-down&quot; lay-options=&quot;{type: &#x27;group&#x27;}&quot;&gt;
      &lt;div class=&quot;layui-menu-body-title&quot;&gt;
        menu item 3 group &lt;i class=&quot;layui-icon layui-icon-up&quot;&gt;&lt;/i&gt;
      &lt;/div&gt;
      &lt;ul&gt;
        &lt;li lay-options=&quot;{id: 1031}&quot;&gt;menu item 3-1&lt;/li&gt;
        &lt;li lay-options=&quot;{id: 1032}&quot;&gt;
          &lt;div class=&quot;layui-menu-body-title&quot;&gt;menu item 3-2&lt;/div&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
    &lt;li class=&quot;layui-menu-item-divider&quot;&gt;&lt;/li&gt;
    &lt;li lay-options=&quot;{id: 104}&quot;&gt;
      &lt;div class=&quot;layui-menu-body-title&quot;&gt;menu item 4&lt;/div&gt;
    &lt;/li&gt;
    &lt;li class=&quot;layui-menu-item-parent&quot; lay-options=&quot;{type: &#x27;parent&#x27;}&quot;&gt;
      &lt;div class=&quot;layui-menu-body-title&quot;&gt;
        menu item 5 
        &lt;i class=&quot;layui-icon layui-icon-right&quot;&gt;&lt;/i&gt;
      &lt;/div&gt;
      &lt;div class=&quot;layui-panel layui-menu-body-panel&quot;&gt;
        &lt;ul&gt;
          &lt;li lay-options=&quot;{id: 1051}&quot;&gt;
            &lt;div class=&quot;layui-menu-body-title&quot;&gt;menu item 5-1&lt;/div&gt;
          &lt;/li&gt;
          &lt;li lay-options=&quot;{id: 1051}&quot;&gt;
            &lt;div class=&quot;layui-menu-body-title&quot;&gt;menu item 5-2&lt;/div&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/li&gt;
    &lt;li lay-options=&quot;{id: 106}&quot;&gt;
      &lt;div class=&quot;layui-menu-body-title&quot;&gt;menu item 6&lt;/div&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
            </pre>
          </div>
          <div class="layui-tab-item">
            <div id="docDemoView1" style="width: 200px;"></div>
          </div>
        </div>
      </div> 
      
      <p>可以看到，它实则是一个 ul li 的层级嵌套，当需要出现「菜单组」和「子级菜单」时，只需要添加相对应的 class 类名即可。</p>
    </div> 
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="type">菜单项类型</a></legend>
    </fieldset>
    <div class="site-text">
      <p>菜单项是由 li 元素组成的，以下将列举几种被支持的菜单项类型</p>
      <table class="layui-table">
        <colgroup>
          <col width="150">
          <col>
          <col width="30%">
        </colgroup>
        <thead>
          <tr>
            <th>类型</th>
            <th>html</th>
            <th>说明</th>
          </tr> 
        </thead>
        <tbody>
          <tr>
            <td>常规菜单项</td>
            <td>&lt;li&gt;&lt;/li&gt;</td>
            <td>无需添加特定 class</td>
          </tr>
          <tr>
            <td>可收缩菜单组</td>
            <td>
              &lt;li class=&quot;layui-menu-item-group layui-menu-item-down&quot; lay-options=&quot;{type: &#x27;group&#x27;}&quot;&gt;&lt;/li&gt;
            </td>
            <td>
              其中<em>layui-menu-item-down</em>为初始展开；<em>layui-menu-item-up</em>为初始收缩。
            </td>
          </tr>
          <tr>
            <td>横向父子菜单</td>
            <td>
              &lt;li class=&quot;layui-menu-item-parent&quot; lay-options=&quot;{type: &#x27;parent&#x27;}&quot;&gt;&lt;/li&gt;
            </td>
            <td>其子级菜单的结构参照上文的「菜单结构」，主要是需包含一层面板元素。</td>
          </tr>
          <tr>
            <td>分割线</td>
            <td>
              &lt;li class=&quot;layui-menu-item-divider&quot;&gt;&lt;/li&gt;
            </td>
            <td>一条横线，用于更好地划分菜单区域</td>
          </tr>
        </tbody>
      </table>
      <p>
        其子级菜单遵循的列表类型也是一样的。需要注意的是，「可收缩菜单组」的子菜单仅需要再嵌套一层 ul 即可；而「横向父子菜单」还需要套一层 <code>div class="layui-panel layui-menu-body-panel"</code>，以便让子菜单层次更加分明。
      </p>
    </div>
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="options">菜单项参数</a></legend>
    </fieldset>
    <div class="site-text">
      <p>在上文中，您可能已经多次注意到 <code>lay-options="{}"</code> 这个属性了，它正是我们所说的菜单项参数。当点击菜单列表时，回调中将会返回该属性所配置的全部参数，其中<code>type</code>参数是组件内部约定的，其它参数可以随意命名。如</p>
      <pre class="layui-code">
&lt;li lay-options="{
  id: 100
  ,title: 'menu item 1'
  ,type: '' //支持的类型有：group、parent，具体用法参见上文
  ,aaa: '任意参数'
}"&gt;内容&lt;/li&gt;      
      </pre>
    </div>
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="on">事件触发</a></legend>
    </fieldset>
    <div class="site-text">
      <p>我们的<em>dropdown</em>组件不仅菜单的基本交互（如点击选中、菜单组展开收缩等）进行了支持，还提供了菜单的事件机制：</p>
      <div class="layui-tab layui-tab-brief layui-code-demo">
        <ul class="layui-tab-title">
          <li class="layui-this">JS</li>
          <li>HTML</li>
        </ul>
        <div class="layui-tab-content layui-border layui-bg-gray">
          <div class="layui-tab-item layui-show">
            <pre class="layui-code" lay-lang="JS">
layui.use('dropdown', function(){
  var dropdown = layui.dropdown;
  
  //菜单点击事件，其中 docDemoMenu1 对应的是菜单结构上的 id 指
  dropdown.on('click(docDemoMenu1)', function(options){
    var othis = $(this); //当前菜单列表的 DOM 对象
    console.log(options); //菜单列表的 lay-options 中的参数
  });
});
            </pre>
          </div>
          <div class="layui-tab-item">
            <pre class="layui-code" lay-lang="HTML">
&lt;div class=&quot;layui-panel&quot;&gt;
  &lt;ul class=&quot;layui-menu&quot; id=&quot;docDemoMenu1&quot;&gt;
    &lt;li lay-options=&quot;{id: 100}&quot;&gt;
      &lt;div class=&quot;layui-menu-body-title&quot;&gt;menu item 1&lt;/div&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;
            </pre>
          </div>
        </div>
      </div>
    </div>
    
 
    
    <fieldset class="layui-elem-field layui-field-title site-title">
      <legend><a name="docend">结语</a></legend>
    </fieldset>
    <div class="site-text">
      <p>本篇所讲解的是基础菜单的静态展示，其提供的是一个基础的结构，事实上它还被动态封装在诸如下拉菜单、右键菜单等场景中。</p>
    </div>
    
    <div class="layui-elem-quote">
  <p>layui - 在每一个细节中，用心与你沟通</p>
</div>
    
  </div>
</div>
<script>
window.global = {
  pageType: 'doc'
  ,preview: function(){
    var preview = document.getElementById('LAY_preview');
    return preview ? preview.innerHTML : '';
  }()
};
</script>
<script async="" src="../../pagead/js/adsbygoogle.js"></script>
<div class="site-tree-mobile layui-hide">
  <i class="layui-icon layui-icon-spread-left"></i>
</div>
<div class="site-mobile-shade"></div>
 
<script src="../../layui/dist/layui.js" ></script>
<script>
layui.config({
  base: '../../static/lay/modules/layui/'
  ,version: '1632428048260'
}).use('global');
</script>
 <script>
global.docDemoCode = document.getElementById('docDemoCode1').innerHTML;
layui.use(['dropdown', 'util', 'layer'], function(){
  var dropdown = layui.dropdown
  ,util = layui.util
  ,layer = layui.layer
  ,$ = layui.jquery;
  
  $('#docDemoView1').html(util.unescape(global.docDemoCode));
  
  dropdown.on('click(docDemoMenu1)', function(obj){
    layer.msg(JSON.stringify(obj))
  });
});
</script>
</body>
</html>